﻿using HandyControl.Controls;
using Prism.Commands;
using Prism.Mvvm;
using SqliteDAL.DAL;
using System.Linq;
using System.Windows.Input;

namespace Prism_DryIoc_WPFDemo.ViewModels
{
    public class LoginViewModel : BindableBase
    {
        private LoginDAL _loginDAL;

        public LoginViewModel(LoginDAL loginDAL)
        {
            this._loginDAL = loginDAL;
        }

        private string userName = "";
        private string password = "";

        public string UserName
        {
            get { return userName; }
            set { SetProperty(ref userName, value); }//应用于双向绑定，自动更新
        }
        public string Password
        {
            get { return password; }
            set { SetProperty(ref password, value); }
        }

        ICommand? loginCommand;
        public ICommand LoginCommand
        {
            get
            {
                if (loginCommand == null)
                {
                    loginCommand = new DelegateCommand<object>(UserLogin);

                }
                return loginCommand;
            }
        }

        void UserLogin(object obj)
        {
            //if (!_loginDAL.AddUser(UserName, Password))
            //{

            //}
           
            //bool res = _loginDAL.AddEntity(new SqliteDAL.Model.Login { Name = "111", Pwd = "333" });

            //var ww = _loginDAL.LoadEntities(c => c.Name == "111").ToList();
            //MessageBox.Show($"{ww.Count}--------{ww[0].Name}--------{ww[0].Pwd}");
            //(obj as Window).DialogResult = true;
        }
    }
}
